<template>
  <el-dialog
    v-el-drag-dialog
    title="订单打印列表"
    :visible.sync="visible"
    width="80%"
    min-width="1024px"
    @close="reset"
  >
    <lb-table
      ref="lbTable"
      border
      highlight-current-row
      element-loading-text="加载中"
      :column="tableData.column"
      min-height="200px"
      :data="tableData.data"
    />
    <div slot="footer" class="dialog-footer">
      <el-button @click="visible = false">
        关闭
      </el-button>
      <el-button :loading="$loadingPlugin.success" type="primary" @click="success">
        打印
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { parseTime } from '@/filters'
  import { batchOrderPrintTable } from '@/api'

  export default {
    name: 'orderDetail',
    filters: {
      parseTime
    },
    data() {
      return {
        visible: false,
        tableData: {
          total: 0,
          column: [
            { type: 'selection', width: '40' },
            { label: '单号', prop: 'orderCode', width: 100, align: 'center' },
            { label: '地址', prop: 'csmAddress', width: 180, align: 'left' },
            { label: '客户名称', prop: 'csmName', width: '', align: 'center' },
            { label: '客户电话', prop: 'csmPhone', width: 120, align: 'center' },
            { label: '备注', prop: 'remark', width: 150, align: 'center' },
            { label: '金额', prop: 'decimalSpare4', width: '', align: 'right' },
            { label: '订单状态', prop: 'orderStatus', width: '', align: 'center' },
            { label: '配送员', prop: 'ownerName', width: '', align: 'center' },
            { label: '下单时间', prop: 'transactTime', width: 200, align: 'center',
              render: (h, { row }) => <span>{ row.transactTime && parseTime(row.transactTime, '{y}-{m}-{d} {h}:{i}:{s}') }</span>
            },
            { label: '商品数量', prop: 'goodsCount', width: 50, align: 'left' },
            { label: '商品详情', prop: 'goodsDesc', width: 250, align: 'left' }
          ],
          data: []
        }
      }
    },
    methods: {
      open(temp) {
        return new Promise(async resolve => {
          this.resolve = resolve
          this.visible = true
          if (temp) {
            const res = await batchOrderPrintTable({ userId: temp.userId })
            this.tableData.data = res.data
            console.log(temp.userId)
          }
        })
      },
      success() {
        this.visible = false
      },
      reset() {
        this.visible = false
      }
    }
  }
</script>

<style lang="scss" scoped>

</style>
